package cn.bugDance.test.infrastructure.repository;

import cn.bugDance.domain.strategy.model.entity.RaffleFactorEntity;
import cn.bugDance.domain.strategy.service.armory.IRaffleStrategyArmory;
import cn.bugDance.domain.strategy.service.dispatch.IRaffleStrategyDispatch;
import cn.bugDance.domain.strategy.service.rule.chain.factory.RuleChainFactory;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

@SpringBootTest
@RunWith(SpringRunner.class)
@Slf4j
public class StrategyAssembleTest {

    @Resource
    private IRaffleStrategyArmory raffleStrategyArmory;
    @Resource
    private IRaffleStrategyDispatch raffleStrategyDispatch;
    @Resource
    private RuleChainFactory ruleChainFactory;

    @Before
    public void init(){
        //raffleStrategyArmory.assembleRaffleStrategy(100001L);
    }

    @Test
    public void test_assemble(){
        //raffleStrategyArmory.assembleRaffleStrategy(100001L);
    }

    @Test
    public void test_randomRaffle(){
        Integer awardId = raffleStrategyDispatch.randomRaffle(100001L);
        log.info("全量抽奖结果: {}", awardId);
    }

    @Test
    public void test_chainFactory(){
        RaffleFactorEntity raffleFactorEntity = new RaffleFactorEntity();
        raffleFactorEntity.setStrategyId(100001L);
        raffleFactorEntity.setUserId("user008");

        RuleChainFactory.RuleChainActionEntity ruleChainActionEntity = ruleChainFactory.openRuleChain(raffleFactorEntity);
        log.info("结果为: {}", JSON.toJSONString(ruleChainActionEntity));
    }
}
